import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
//element-plus按需引入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
//import all svg
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
//mock
import { viteMockServe } from 'vite-plugin-mock'
import { createHtmlPlugin } from 'vite-plugin-html'
import settings from './src/settings'
//jsx
import vueJsx from '@vitejs/plugin-vue-jsx'

function resolve(dir: string) {
  return path.join(__dirname, dir)
}
 
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': resolve('src')
    }
  },
  plugins: [
    vue(),
    VueSetupExtend(),
    vueJsx(),
    AutoImport({
      imports: ['vue', 'vue-router'],
      resolvers: [
        ElementPlusResolver()
      ],
      dts: './types/auto-imports.d.ts'
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
      ],
      dts: './types/components.d.ts'
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
      symbolId: 'icon-[dir]-[name]'
    }),
    viteMockServe({
      supportTs: false,
      logger: true,
      watchFiles: true,
      mockPath: './mock'
    }),
    createHtmlPlugin({
      inject: {
        // Inject data into ejs template
        data: {
          title: settings.title
        }
      }
    })
  ],
  server: {
    hmr: true,
  },
})
